Imports System.Data
Imports System.Data.SqlClient

Public Class DTrimestre
    Dim oCnn As New DConexion
    Public Function calcularPromedioTrimestral(ByVal trimestre As Entidades.ETrimestre, ByVal alumno As Entidades.EAlumno, ByVal asignatura As Integer, ByVal ciclo As Integer) As Single
        Dim Cmd As New SqlCommand
        Dim suma As Single = 0
        Dim cant As Integer = 0
        Dim promedio As Double = 0.0
        Try
            oCnn.abrirConexion()
            Cmd.Connection = oCnn.obtenerConexion
            Cmd.CommandType = CommandType.StoredProcedure
            Cmd.CommandText = "BuscarNotasTrimestrexAlumno"
            Cmd.Parameters.AddWithValue("@trimestre", trimestre.Orden)
            Cmd.Parameters.AddWithValue("@alumno", alumno.Num_Legajo)
            Cmd.Parameters.AddWithValue("@asignatura", asignatura)
            Cmd.Parameters.AddWithValue("@ciclo", ciclo)
            Dim dr As SqlDataReader
            dr = Cmd.ExecuteReader
            Do While dr.Read
                suma = suma + CDbl(dr("calificacion"))
                cant = cant + 1
            Loop
            promedio = (suma / cant)
        Catch ex As Exception
            Throw New ArgumentException(ex.Message)
        End Try
        oCnn.cerrarConexion()
        Return promedio
    End Function

    Public Function buscarNotasAlumno(ByVal trimestre As Entidades.ETrimestre, ByVal alumno As Entidades.EAlumno, ByVal asignatura As Integer, ByVal ciclo As Integer) As List(Of Entidades.ENota)
        Dim Cmd As New SqlCommand
        Dim listado As New List(Of Entidades.ENota)
        Try
            oCnn.abrirConexion()
            Cmd.Connection = oCnn.obtenerConexion
            Cmd.CommandType = CommandType.StoredProcedure
            Cmd.CommandText = "BuscarNotasTrimestrexAlumno"
            Cmd.Parameters.AddWithValue("@trimestre", trimestre.Orden)
            Cmd.Parameters.AddWithValue("@alumno", alumno.Num_Legajo)
            Cmd.Parameters.AddWithValue("@asignatura", asignatura)
            Cmd.Parameters.AddWithValue("@ciclo", ciclo)
            Dim dr As SqlDataReader
            dr = Cmd.ExecuteReader
            Do While dr.Read
                Dim nota As New Entidades.ENota
                nota.NroNota = dr("nronota")
                nota.Calificacion = dr("calificacion")
                listado.Add(nota)
            Loop
            dr.Close()
        Catch ex As Exception
            Throw New ArgumentException(ex.Message)
        End Try
        oCnn.cerrarConexion()
        Return listado
    End Function
End Class
